package com.cndw.kungfu.controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cndw.kungfu.comm.AccessClose;
import com.cndw.kungfu.comm.AccessFlag;
import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.config.ConstantsCost;
import com.cndw.kungfu.config.ConstantsDayIntKey;
import com.cndw.kungfu.config.ConstantsFlag;
import com.cndw.kungfu.config.ConstantsIntKey;
import com.cndw.kungfu.config.ConstantsLevel;
import com.cndw.kungfu.config.ConstantsLog;
import com.cndw.kungfu.config.ConstantsModel;
import com.cndw.kungfu.config.ConstantsRadio;
import com.cndw.kungfu.config.GoodsEffectConfig;
import com.cndw.kungfu.config.RMK;
import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.ext.LangUtil;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.ext.TimeProcesser;
import com.cndw.kungfu.model.ActivitySerialize;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.HolidayCommSerialize;
import com.cndw.kungfu.model.activity.holiday.ActTaskConfig;
import com.cndw.kungfu.model.activity.holiday.KiteData;
import com.cndw.kungfu.model.activity.holiday.MMFlowerData;
import com.cndw.kungfu.model.activity.holiday.MMFlowerLog;
import com.cndw.kungfu.model.activity.holiday.MidAutumnData;
import com.cndw.kungfu.model.activity.holiday.MidAutumnParams;
import com.cndw.kungfu.model.activity.holiday.PoetryData;
import com.cndw.kungfu.model.activity.holiday.ZongZiSteamer;
import com.cndw.kungfu.model.general.ModeExpConfig;
import com.cndw.kungfu.model.goods.PlayerBoxs;
import com.cndw.kungfu.model.goods.domain.SubPops;
import com.cndw.kungfu.model.goods.domain.SysModeAwards;
import com.cndw.kungfu.model.pvp.api.CommApiClient;
import com.cndw.kungfu.model.pvp.api.FlowerApiClient;
import com.cndw.kungfu.model.sys.ChatMain;
import com.cndw.kungfu.model.sys.LogServer;
import com.cndw.kungfu.vo.EventNotice;
import com.cndw.kungfu.vo.goodsvo.GoodsVO;
import com.cndw.rpg.annotation.Controller;
import com.cndw.rpg.framework.ResponseMessage;
import com.cndw.rpg.framework.Session;
import com.cndw.rpg.framework.SessionHolder;

@Controller
@AccessFlag(ConstantsFlag.holiday)
public class HolidayController {

	/**
	 * 粽子活动界面显示
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage zongziShow(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int zzfNum = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.zzfNum);
		int haveTime = player.getTodayOnLine() - zzfNum * ConstantsModel.zzFreeTime;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("zzfNum", zzfNum);
		map.put("zzFreeMax", ConstantsModel.zzFreeNum);
		map.put("needOnline", (ConstantsModel.zzFreeTime - haveTime));
		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 免费领取粽子
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage zongziFree(Session session) {
		if (session.getUid() >0 ) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());

		int zzfNum = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.zzfNum);
		if (zzfNum >= ConstantsModel.zzFreeNum) {
			return null;
		}
		int haveTime = player.getTodayOnLine() - zzfNum * ConstantsModel.zzFreeTime;
		if (haveTime < ConstantsModel.zzFreeTime) {
			return null;
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		zzfNum = zzfNum + 1;
		haveTime -= ConstantsModel.zzFreeTime;

		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.zzfNum, zzfNum);
		Context.getGoodsServer().giveGoodsBing(session.getUid(), GoodsEffectConfig.zzGoodsId[0], 1, 1);
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(GoodsEffectConfig.zzGoodsId[0]);
		LogServer.recordLog(player, ConstantsLog.activity, 90101, goodsMode.getName(), player.getPlayerBoxs().getStackNum(GoodsEffectConfig.zzGoodsId[0]));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("zzfNum", zzfNum);
		map.put("zzFreeMax", ConstantsModel.zzFreeNum);
		map.put("needOnline", ConstantsModel.zzFreeTime - haveTime);
		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 粽子兑换
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage zongziExchange(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());

		PlayerBoxs playerBoxs = player.getPlayerBoxs();
		int brokenNum = playerBoxs.getStackNum(GoodsEffectConfig.zongziBrokenId);
		int num = brokenNum / 10;
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(GoodsEffectConfig.zzGoodsId[2]);

		int block = NumberProcesser.ceil(num, goodsMode.getMaxStack());
		if (!playerBoxs.checkBlack(block)) {
			return ResponseMessage.errMsg(LanguageLib.get("comm.player.boxmin", block));
		}
		playerBoxs.costGoods(GoodsEffectConfig.zongziBrokenId, num * 10);
		Context.getGoodsServer().giveGoods(session.getUid(), GoodsEffectConfig.zzGoodsId[2], num);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("costNum", num * 10);
		map.put("num", num);
		String brokenName = Context.getGoodsServer().getModeById(GoodsEffectConfig.zongziBrokenId).getName();
		int stackNum = playerBoxs.getStackNum(GoodsEffectConfig.zzGoodsId[2]);
		LogServer.recordLog(player, ConstantsLog.activity, 90102, num * 10, brokenName, num, goodsMode.getName(), stackNum);

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 蒸笼显示界面
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage zzSteamer(Session session) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("awardNum", ZongZiSteamer.getAward(session.getUid()));
		map.put("awardTime", ZongZiSteamer.getCurrentEndTime());
		map.put("currentStartTime", ZongZiSteamer.getCurrentStartTime());
		map.put("activityEndTime", ZongZiSteamer.getActivityEndTime());
		map.put("step", ZongZiSteamer.getStep());
		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 蒸笼加火
	 * 
	 * @param session
	 * @param free
	 * @return
	 */
	@AccessClose
	public ResponseMessage zzAddFire(Session session, boolean free) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < 30) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level", 30));
		}
		int awardNum = ZongZiSteamer.getAward(session.getUid());
		if (!ZongZiSteamer.canFire() || ZongZiSteamer.canGot()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.zongzi.nofire"));
		}
		if (free && awardNum != 0) {
			return null;
		}
		if (awardNum == 0 && !free) {
			return null;
		}
		if (!free) {
			if (player.getGoldAll() < ConstantsModel.zzFrieGold) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
			}
			player.alterGoldAll(-ConstantsModel.zzFrieGold);
			ZongZiSteamer.fireAdd(session.getUid(), player.getLevel());
			awardNum++;
		} else {
			awardNum = 3;
		}
		ZongZiSteamer.awardAlter(session.getUid(), awardNum);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("awardNum", awardNum);
		if (!free) {
			int awardTime = ZongZiSteamer.getCurrentEndTime();
			map.put("gold", player.getGold());
			map.put("goldBing", player.getGoldBing());
			map.put("awardTime", awardTime);
			EventNotice eventNotice = new EventNotice(ConstantsRadio.holiday, ConstantsRadio.holiday_Zongzi);
			eventNotice.put("awardTime", awardTime);
			eventNotice.broadCastAllOnLine();
			ChatMain.systemMessage(LanguageLib.get("holiday.zongzi.firechat", player.getPlayerName()));

			LogServer.costEventLog(session.getUid(), ConstantsModel.zzFrieGold, ConstantsCost.zzFire);
		}
		LogServer.recordLog(player, ConstantsLog.activity, 90103, free ? 0 : ConstantsModel.zzFrieGold, awardNum);

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 领取奖励
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage zzAwardGot(Session session) {
		if (session.getUid() >0 ) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int awardNum = ZongZiSteamer.getAward(session.getUid());
		if (awardNum <= 0) {
			return null;
		}
		if (!ZongZiSteamer.canGot()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.zongzi.nogot"));
		}
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(GoodsEffectConfig.zzGoodsId[0]);

		int block = NumberProcesser.ceil(awardNum, goodsMode.getMaxStack());
		if (!player.getPlayerBoxs().checkBlack(block)) {
			return ResponseMessage.errMsg(LanguageLib.get("comm.player.boxmin", block));
		}
		ZongZiSteamer.awardAlter(session.getUid(), -1);
		Context.getGoodsServer().giveGoodsBing(session.getUid(), GoodsEffectConfig.zzGoodsId[0], awardNum, 1);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("awardNum", awardNum);
		ChatMain.systemMessage(LanguageLib.get("holiday.zongzi.gotchat", player.getPlayerName()));

		LogServer.recordLog(player, ConstantsLog.activity, 90104, awardNum, goodsMode.getName());

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 提交礼券
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage zzLiQuanAdd(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (!player.getPlayerBoxs().isHaveGoods(GoodsEffectConfig.zongziLiQuanId)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.zongzi.noliquan"));
		}
		if (ZongZiSteamer.getActivityEndTime() <= TimeProcesser.getUnixTime()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.zongzi.linoadd"));
		}
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(GoodsEffectConfig.zongziLiQuanId);
		player.getPlayerBoxs().costGoods(GoodsEffectConfig.zongziLiQuanId, 1);
		ActivitySerialize.getInstance().zongZiLiQuanAdd(session.getUid());
		ActivitySerialize.getInstance().commitSync();

		Map<String, Object> map = new HashMap<String, Object>();
		int liQuanAdd = ActivitySerialize.getInstance().zongziLiQuanGet(session.getUid());
		map.put("liQuanAdd", liQuanAdd);

		LogServer.recordLog(player, ConstantsLog.activity, 90105, goodsMode.getName(), liQuanAdd);

		return ResponseMessage.ticpMsg(LanguageLib.get("holiday.zongzi.liquansuc"));

	}

	@AccessClose
	public ResponseMessage zzLiQuanShow(Session session) {
		int liQuanAdd = ActivitySerialize.getInstance().zongziLiQuanGet(session.getUid());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("liQuanAdd", liQuanAdd);
		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 抽取礼券奖励
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage zzLiQuanAward(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (ZongZiSteamer.getActivityEndTime() >= TimeProcesser.getUnixTime()) {
			// return
			// ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.zongzi.timeaward"));
		}
		int liQuanAdd = ActivitySerialize.getInstance().zongziLiQuanGet(session.getUid());
		if (liQuanAdd <= 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.zongzi.noaward"));
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		int indexId = NumberProcesser.rateIndex(ConstantsModel.zzLiQuanAwardRate, 1000);
		int awardId = ConstantsModel.zzLiQuanAwardIds[indexId];

		liQuanAdd--;
		ActivitySerialize.getInstance().zongZiLiQuanSet(session.getUid(), liQuanAdd);

		GoodsMode goodsMode = Context.getGoodsServer().getModeById(awardId);
		Context.getGoodsServer().giveGoods(session.getUid(), awardId, 1);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("liQuanAdd", liQuanAdd);
		map.put("awardName", goodsMode.getName());
		map.put("awardId", awardId);
		LogServer.recordLog(player, ConstantsLog.activity, 90106, goodsMode.getName(), liQuanAdd);
		if (goodsMode.getColor() >= 3) {
			ChatMain.systemMessageDelay(LanguageLib.get("holiday.zongzi.liquanaward",player.getPlayerName(),LangUtil.makeHtml(goodsMode.getColor(), goodsMode.getName())), 3);
				
		}
		return ResponseMessage.getSuccMessage(map);
	}
	/**
	 * 显示情人节活动面板
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage loverDayShow(Session session, long targetId) {
		if (session.getUid() == targetId) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		Player targetPlayer = Context.getPlayerServer().getByPlayerId(targetId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("awardGet", player.getDataInfo().intDataGet(ConstantsIntKey.lda));
		map.put("tSendNum", HolidayCommSerialize.getInstance().getLoverDayData().getSendNum(targetId));
		map.put("tReceiveNum", HolidayCommSerialize.getInstance().getLoverDayData().getReceiveNum(targetId));
		map.put("mSendNum", HolidayCommSerialize.getInstance().getLoverDayData().getSendNum(session.getUid()));
		map.put("mReceiveNum", HolidayCommSerialize.getInstance().getLoverDayData().getReceiveNum(session.getUid()));
		map.put("freeTimes", ConstantsModel.loverDayFFreeTimes - player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.ldf));
		map.put("targetVId", targetPlayer.getVocationId());
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 情人节送花
	 * 
	 * @param session
	 * @param targetId 
	 * @param type 0 9朵 1 99朵 2 999朵
	 * @return
	 */
	@AccessClose
	public ResponseMessage loverDayFlower(Session session, long targetId, int type) {
		//活动时间限制
		if (TimeProcesser.getUnixTime() >= HolidayCommSerialize.getInstance().getLoverDayData().getEndtime()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.loverday.timeout"));
		}
		if (type < 0 || type > 2) {
			return null;
		}
		if (session.getUid() == targetId) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int freeUsed = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.ldf);
		int costGold = 0;
		if (type == 0 && freeUsed < ConstantsModel.loverDayFFreeTimes && player.getLevel() >= ConstantsLevel.lv42LoverDayFree) {
			player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.ldf, 1);
			player.getDataInfo().commitSync();
		} else {
			costGold = ConstantsModel.loverDayFCost[type] ;
		}
		if (player.getGoldAll() < costGold) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		if (costGold > 0) {
			player.alterGoldAll(-costGold);
			LogServer.costEventLog(session.getUid(), costGold, ConstantsCost.loverDayFlower);
			player.commitSync();
		}
		
		int num = ConstantsModel.loverDayFCost[type];
		
		HolidayCommSerialize.getInstance().getLoverDayData().alterSenderMap(session.getUid(), num);
		HolidayCommSerialize.getInstance().getLoverDayData().alterReceiverMap(targetId, num);
		HolidayCommSerialize.getInstance().getLoverDayData().sendsAdd(session.getUid(), targetId, type);
		//记录赠送
		HolidayCommSerialize.getInstance().commitSync();
		
		Player targetPlayer = Context.getPlayerServer().getByPlayerId(targetId);
		//事件通知
		if (targetPlayer.isOnline()) {
			EventNotice eventNotice = new EventNotice(ConstantsRadio.holiday, ConstantsRadio.holiday_ldFlowerOnce);
			eventNotice.put("senderName", player.getPlayerName()); 
			eventNotice.put("senderId", player.getPlayerId()); 
			eventNotice.put("type", type);
			eventNotice.put("senderVId", player.getVocationId());
			eventNotice.broadcast(targetId);
		} else {
			String content = LanguageLib.get("holiday.loverday.mailcontent", player.getPlayerName(), num, player.getPlayerId(), player.getPlayerName(), player.getVocationId());
			Context.getMessageServer().sendMail(targetId, targetPlayer.getPlayerName(), session.getUid(), player.getPlayerName(),
					LanguageLib.get("holiday.loverday.mailtitle"), content);
		}
		
		if (type > 0) {
			EventNotice aNotice = new EventNotice(ConstantsRadio.holiday, ConstantsRadio.holiday_ldFlowerRain);
			aNotice.put("aSenderName", player.getPlayerName());
			aNotice.put("aReceiverName", targetPlayer.getPlayerName());
			aNotice.put("aType", type);
			aNotice.broadCastAllOnLine();
		}
		
//		if (type > 0) {
//			ChatMain.systemMessage(LanguageLib.get(type == 1 ? "holiday.loverday.flower1" : "holiday.loverday.flower2", player.getPlayerName(), targetPlayer.getPlayerName()));
//		}
		
		LogServer.recordLog(player, ConstantsLog.activity, 90401, costGold, num, targetPlayer.getPlayerName(), HolidayCommSerialize.getInstance().getLoverDayData().getSendNum(session.getUid()));
		LogServer.recordLog(targetPlayer, ConstantsLog.activity, 90402, player.getPlayerName(), num, HolidayCommSerialize.getInstance().getLoverDayData().getReceiveNum(targetId));
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		map.put("tSendNum", HolidayCommSerialize.getInstance().getLoverDayData().getSendNum(targetId));
		map.put("tReceiveNum", HolidayCommSerialize.getInstance().getLoverDayData().getReceiveNum(targetId));
		map.put("mSendNum", HolidayCommSerialize.getInstance().getLoverDayData().getSendNum(session.getUid()));
		map.put("mReceiveNum", HolidayCommSerialize.getInstance().getLoverDayData().getReceiveNum(session.getUid()));
		map.put("freeTimes", ConstantsModel.loverDayFFreeTimes - player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.ldf));
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 领取情人节送花奖励
	 * 
	 * @param session
	 * @param step 0 100点  1 999点 2 9999点 3 49999点
	 * @return
	 */
	@AccessClose
	public ResponseMessage loverDayAward(Session session, int step) {
		if (step < 0 || step > 3) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int awardGet = player.getDataInfo().intDataGet(ConstantsIntKey.lda);
		if ((awardGet & (1 << step)) > 0) {//已领取
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.loverday.geterr"));
		}
		int sendNum = HolidayCommSerialize.getInstance().getLoverDayData().getSendNum(session.getUid());
	
		Map<String, Object> map = new HashMap<String, Object>();
		if (sendNum >= ConstantsModel.loverDayAward[step][0]) {
			if (!player.getPlayerBoxs().checkBlack(1)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
			}
				
			Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsModel.loverDayAward[step][1], 1, 1);
			GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsModel.loverDayAward[step][1]);
			if (goodsMode == null) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.sys"));
			}
			LogServer.recordLog(player, ConstantsLog.activity, 90403, goodsMode.getName(), 1, sendNum);
			player.getDataInfo().intDataSet(ConstantsIntKey.lda, awardGet | (1 << step));
			player.getDataInfo().commitSync();
			
			map.put("goodsName", goodsMode.getName());
		}
		
		map.put("awardGet", player.getDataInfo().intDataGet(ConstantsIntKey.lda));
		return ResponseMessage.getSuccMessage(map);
	}
	/**
	 * 获取情人节送花排行
	 * 
	 * @param session
	 * @param type 1 情圣排行 2万人迷排行
	 * @return
	 */
	@AccessClose
	public ResponseMessage loverDayRanking(Session session, int type) {
		if (type < 1 || type > 2) {
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ranking", type == 1 ? HolidayCommSerialize.getInstance().getLoverDayData().getSenderRanking() : HolidayCommSerialize.getInstance().getLoverDayData().getReceiverRanking());
		return ResponseMessage.getSuccMessage(map);
	}
	/**
	 * 回吻
	 * 
	 * @param session
	 * @param targetId 被回吻者id
	 * @param type 0 9朵 1 99朵 2 999朵
	 * @return
	 */
	@AccessClose
	public ResponseMessage kissBack(Session session, long targetId, int type) {
		if (type < 0 || type > 2) {
			return null;
		}
		if (targetId == session.getUid()) {
			return null;
		}
		boolean suc = HolidayCommSerialize.getInstance().getLoverDayData().sendsChk(targetId, session.getUid(), type);
		if (!suc) {
			return null;
		}
		
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		Player targetPlayer = Context.getPlayerServer().getByPlayerId(targetId);
		targetPlayer.alterAsset(ConstantsModel.loverDayKissGet[type]);
		targetPlayer.commitSync();
		
		EventNotice eventNotice = new EventNotice(ConstantsRadio.holiday, ConstantsRadio.holiday_ldKiss);
		eventNotice.put("senderName", player.getPlayerName()); 
		eventNotice.put("asset", targetPlayer.getAsset());
		eventNotice.put("assetGet", ConstantsModel.loverDayKissGet[type]);
		eventNotice.broadcast(targetId);
		
		int num = ConstantsModel.loverDayFCost[type];
		LogServer.recordLog(targetPlayer, ConstantsLog.activity, 90404, num, player.getPlayerName(), ConstantsModel.loverDayKissGet[type], targetPlayer.getAsset());
		
		return ResponseMessage.getSuccMessage(true);
	}
	
	/**
	 * 中秋节赏月活动显示
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage moonShow(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv30Moon) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv30Moon);
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ms", HolidayCommSerialize.getInstance().getMidAutumnData().getMoonScore(session.getUid()));
		map.put("mt", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.mt));
		map.put("mas", player.getDataInfo().intDataGet(ConstantsIntKey.mag));
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 中秋节赏月
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage moonEnjoy(Session session) {
		long playerId = session.getUid();
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (player.getLevel() < ConstantsLevel.lv30Moon) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv30Moon);
		}
		MidAutumnData midAutumnData = HolidayCommSerialize.getInstance().getMidAutumnData();
		if (midAutumnData.chkMoonEnd()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr"));
		}
		
		int mTimes = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.mt);
		if (mTimes >= ConstantsModel.moonMax) {
			return null;
		}
		int costGold = ConstantsModel.moonCost[mTimes];
		if (player.getGoldAll() < costGold) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		
		if (!player.getPlayerBoxs().checkBlack(1)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1)); 
		}
		
		Context.getGoodsServer().giveGoodsBing(playerId, 103536, 1, 1);//发送赏月礼包
		
		if (costGold > 0) {
			player.alterGoldAll(-costGold);
			LogServer.costEventLog(playerId, costGold, ConstantsCost.moonEnjoy);
			player.commitSync();
		}
		midAutumnData.alterMoonScore(playerId, 1);
		midAutumnData.commitSync();
		player.getDataInfo().getEveryDay().intDataAlter(ConstantsDayIntKey.mt, 1);
		player.getDataInfo().commitSync();
		
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(103536);
		LogServer.recordLog(player, ConstantsLog.activity, 90431, costGold, goodsMode.getName(), 1, midAutumnData.getMoonScore(playerId));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ms", midAutumnData.getMoonScore(playerId));
		map.put("mt", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.mt));
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		return ResponseMessage.getSuccMessage(map);
	}
	
	
	/**
	 * 领取中秋节赏月奖励
	 * 
	 * @param session
	 * @param step 
	 * @return
	 */
	@AccessClose
	public ResponseMessage moonAward(Session session, int step) {
		long playerId = session.getUid();
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (player.getLevel() < ConstantsLevel.lv30Moon) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv30Moon);
		}
		if (HolidayCommSerialize.getInstance().getMidAutumnData().chkMoonEnd()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr"));
		}
		
		if (step < 1 || step > 5) {
			return null;
		}
		int nextStep = player.getDataInfo().intDataGet(ConstantsIntKey.mag) + 1;
		if (step != nextStep) {
			return null;
		}
		int mScore = HolidayCommSerialize.getInstance().getMidAutumnData().getMoonScore(playerId);
		if (mScore < ConstantsModel.moonAward[step - 1][0]) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.moon.notenough"));
		}
		int getNum = ConstantsModel.moonAward[step - 1][2];
		if (!player.getPlayerBoxs().checkBlack(getNum)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", getNum)); 
		}
		Context.getGoodsServer().giveGoodsBing(playerId, ConstantsModel.moonAward[step -1][1], getNum, 1);
		
		player.getDataInfo().intDataSet(ConstantsIntKey.mag, step);
		player.getDataInfo().commitSync();
		
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsModel.moonAward[step -1][1]);
		LogServer.recordLog(player, ConstantsLog.activity, 90432, goodsMode.getName(), getNum, mScore);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mas", player.getDataInfo().intDataGet(ConstantsIntKey.mag));
		map.put("getNum", getNum);
		return ResponseMessage.getSuccMessage(map);
	}
	/**
	 * 烟花显示
	 * 
	 * @param session
	 * @param targetId
	 * @return
	 */
	@AccessClose
	public ResponseMessage fireworkShow(Session session, long targetId) {
		Player sPlayer = Context.getPlayerServer().getByPlayerId(session.getUid());
		
		if (sPlayer.getLevel() < ConstantsLevel.lv30Firework) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level", ConstantsLevel.lv30Firework));
		}
		
		Player tPlayer = Context.getPlayerServer().getByPlayerId(targetId);
		if (tPlayer != null && tPlayer.getLevel() < ConstantsLevel.lv30Firework) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.firework.invlevel", ConstantsLevel.lv30Firework));
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		List<GoodsVO> goodsVOs = new ArrayList<GoodsVO>();
		for (Integer gId : GoodsEffectConfig.fireworkIds) {
			GoodsMode goodsMode = Context.getGoodsServer().getModeById(gId);
			goodsVOs.add(goodsMode.toGoodsVO());
		}
		map.put("goodsVOs", goodsVOs);
		map.put("fwScore", HolidayCommSerialize.getInstance().getMidAutumnData().getFwScore(session.getUid()));
		map.put("tVId", tPlayer != null ? tPlayer.getVocationId() : 0);
		boolean free = sPlayer.getLevel() >= ConstantsLevel.lv42FireworkFree && (sPlayer.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm) & 1) == 0;
		map.put("free", free);
		map.put("ag", sPlayer.getDataInfo().intDataGet(ConstantsIntKey.fwg) > 0);
		map.put("fwt", sPlayer.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.fwt));
		return ResponseMessage.getSuccMessage(map);
	}
	/**
	 * 烟花排行
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage fireworkRank(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv30Firework) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level", ConstantsLevel.lv30Firework));
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ranking", HolidayCommSerialize.getInstance().getMidAutumnData().getFwRanking());
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 燃放烟花
	 * 
	 * @param session
	 * @param targetId
	 * @param type  0 初级烟花 1 中级 2 高级 3 超级
	 * @return
	 */
	@AccessClose
	public ResponseMessage fireworkEnjoy(Session session, long targetId, int type) {
		
		if (type < 0 || type > 3) {
			return null;
		}
		if (session.getUid() == targetId) {
			return null;
		}
		Player sPlayer = Context.getPlayerServer().getByPlayerId(session.getUid());
		
		if (sPlayer.getLevel() < ConstantsLevel.lv30Firework) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level", ConstantsLevel.lv30Firework));
		}
		
		MidAutumnData midAutumnData = HolidayCommSerialize.getInstance().getMidAutumnData();
		if (midAutumnData.chkFwEnd()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr"));
		}

		Player tPlayer = Context.getPlayerServer().getByPlayerId(targetId);
		if (tPlayer != null && tPlayer.getLevel() < ConstantsLevel.lv30Firework) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.firework.invlevel", ConstantsLevel.lv30Firework));
		}
		
		if (!sPlayer.getPlayerBoxs().checkBlack(1)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1)); 
		}
		if (type == 3 && tPlayer != null) {//超级烟花不能邀请
			return null;
		}
		boolean isFree = type == 0 && sPlayer.getLevel() >= ConstantsLevel.lv42FireworkFree && (sPlayer.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm) & 1) <= 0;
		boolean isHave = sPlayer.getPlayerBoxs().isHaveGoods(GoodsEffectConfig.fireworkIds[type]);
		int costGold = !isFree && !isHave ? ConstantsModel.fireworkCost[type] : 0;
		if (costGold > 0 && sPlayer.getGoldAll() < costGold) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		
		if (tPlayer != null && !tPlayer.isOnline()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.firework.offline"));
		}
		
		int sAssetGet = sPlayer.getLevel() * ConstantsModel.fireworkAwardS[type][0];
		int sExpGet = sPlayer.getLevel() * ConstantsModel.fireworkAwardS[type][1];
		if (type == 0) {
			int fwt = sPlayer.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.fwt) + 1;
			if (fwt > 10) {
				int coff = 100 - 2 * (fwt - 10);
				coff = coff < 10 ? 10 : coff;
				sAssetGet = sAssetGet * coff / 100;
				sExpGet = sExpGet * coff / 100;
			}
		}
		
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsModel.fireworkAwardS[type][2], 1, 1);
		sPlayer.alterAsset(sAssetGet);
		sPlayer.alterExp(sExpGet);
		sPlayer.commitSync();
		
		//广播
		if (tPlayer != null) {//邀请共享
			int assetGet = tPlayer.getLevel() * ConstantsModel.fireworkAwardT[type][0];
			int expGet = tPlayer.getLevel() * ConstantsModel.fireworkAwardT[type][1];
			if (type == 0) {
				assetGet = sAssetGet / 2;
				expGet = sExpGet / 2;
			} else if (type == 2) {
				int coff =  tPlayer.getLevel() > 80 ? 100 : tPlayer.getLevel() > 40 ? 10 : 1;
				expGet = coff * expGet;
			}
			boolean goodsGet = false;
			if (tPlayer.getPlayerBoxs().checkBlack(1)) {
				Context.getGoodsServer().giveGoodsBing(targetId, ConstantsModel.fireworkAwardT[type][2], 1, 1);
				goodsGet = true;
			}
			tPlayer.alterAsset(assetGet);
			tPlayer.alterExp(expGet);
			tPlayer.commitSync();
			
			EventNotice notice = new EventNotice(ConstantsRadio.holiday, ConstantsRadio.holiday_fwInvite);
			notice.put("sId", session.getUid());
			notice.put("sName", sPlayer.getPlayerName());
			notice.put("sVId", sPlayer.getVocationId());
			notice.put("asset", tPlayer.getAsset());
			notice.put("assetGet", assetGet);
			notice.put("expGet", expGet);
			notice.put("type", type);
			notice.put("goodsGet", goodsGet);
			notice.broadcast(targetId);
			GoodsMode tGoodsMode = Context.getGoodsServer().getModeById(ConstantsModel.fireworkAwardT[type][2]);
			LogServer.recordLog(tPlayer, ConstantsLog.activity, 90442, type, assetGet, expGet, goodsGet ? tGoodsMode.getName() : null, goodsGet ? 1 : 0, session.getUid());
		}
		
		if (type >= 1) {//奖励本服其它在线玩家
			MidAutumnParams fp = new MidAutumnParams();
			fp.setS(session.getUid());
			fp.setSid(ConstantsConfig.getSysCgServiceId());
			fp.setType(type);
			fp.setT(targetId);
			fp.setSn(sPlayer.getPlayerName());
			if (tPlayer != null) {
				fp.setTn(tPlayer.getPlayerName());
			}
			Collection<Long> ids = SessionHolder.getInstance().onlineIds();
			ids.remove(session.getUid());
			ids.remove(targetId);
			MidAutumnData.awardOthers(ids, fp);
			if (type == 3) {//全服广播
				CommApiClient.allMessage(fp);
			}
		} 
		
		if (isFree) {
			sPlayer.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.comm, sPlayer.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm) | 1);
			sPlayer.getDataInfo().commitSync();
		} else if (isHave) {
			sPlayer.getPlayerBoxs().costGoods(GoodsEffectConfig.fireworkIds[type], 1);
		} else {
			sPlayer.alterGoldAll(-costGold);
			LogServer.costEventLog(session.getUid(),costGold, ConstantsCost.fwEnjoy);
		}
		
		if (type == 0) {
			sPlayer.getDataInfo().getEveryDay().intDataAlter(ConstantsDayIntKey.fwt, 1);
			sPlayer.getDataInfo().commitSync();
		}
		
		midAutumnData.alterFwScore(session.getUid(), ConstantsModel.fireworkCost[type]);
		midAutumnData.commitSync();
		
		GoodsMode fireworkMode = Context.getGoodsServer().getModeById(GoodsEffectConfig.fireworkIds[type]);
		GoodsMode sGoodsMode = Context.getGoodsServer().getModeById(ConstantsModel.fireworkAwardS[type][2]);
		LogServer.recordLog(sPlayer, ConstantsLog.activity, 90441, type, fireworkMode.getName(), isFree || costGold > 0 ? 0 : 1, costGold, sAssetGet, sExpGet, sGoodsMode.getName(), 1, targetId);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("fwScore", midAutumnData.getFwScore(session.getUid()));
		boolean free = sPlayer.getLevel() >= ConstantsLevel.lv42FireworkFree && (sPlayer.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm) & 1) == 0;
		map.put("free", free);
		map.put("asset", sPlayer.getAsset());
		map.put("gold", sPlayer.getGold());
		map.put("goldBing", sPlayer.getGoldBing());
		map.put("expGet", sExpGet);
		map.put("assetGet", sAssetGet);
		map.put("fwt", sPlayer.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.fwt));
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 领取燃放烟花奖励
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage fireworkAward(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		
		if (player.getLevel() < ConstantsLevel.lv30Firework) {
			return null;
		}
		
		if (HolidayCommSerialize.getInstance().getMidAutumnData().chkFwEnd()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr"));
		}
		
		int score = HolidayCommSerialize.getInstance().getMidAutumnData().getFwScore(session.getUid());
		if (score < ConstantsModel.fireworkAwardNeed) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.firework.notenough"));
		}
		
		if (player.getDataInfo().intDataGet(ConstantsIntKey.fwg) > 0) {//已领取
			return null;
		}
		
		if (!player.getPlayerBoxs().checkBlack(1)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1)); 
		}
		
		Context.getGoodsServer().giveGoodsBing(session.getUid(), 103565, 1, 1);
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(103565);
		
		player.getDataInfo().intDataSet(ConstantsIntKey.fwg, 1);
		player.getDataInfo().commitSync();
		LogServer.recordLog(player, ConstantsLog.activity, 90444, goodsMode.getName(), 1, score);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ag", player.getDataInfo().intDataGet(ConstantsIntKey.fwg) > 0);
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 主播献花界面
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage mmFlowerShow(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f", MMFlowerData.getInstance().weekMapGet(session.getUid()));
		map.put("free", (player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm) & ConstantsDayIntKey.comm_3) == 0);
		return ResponseMessage.getSuccMessage(map);
	}
	@AccessClose
	public ResponseMessage mmFlowerLog(Session session) {
		return FlowerApiClient.getFlowerLog();
	}
	
	/**
	 * 主播献花
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	@AccessClose
	public ResponseMessage mmFlower(Session session, int type, int mmId) {
		if (type < 0 || type > 3 || mmId < 1 || mmId > 4) {
			return null;
		}
		MMFlowerData mmFlowerData = MMFlowerData.getInstance();
		if (mmFlowerData.isForbidTime()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.mmflower.forbid"));
		}
		
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		int comm = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm);
		boolean free = type == 0 && (comm & ConstantsDayIntKey.comm_3) == 0;
		if (!free && player.getGoldAll() < ConstantsModel.mmFlowerGold[type]) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		
		StringBuffer logSB = new StringBuffer();
		if (type >= 1) {
			SysModeAwards sysAwards = SysModeAwards.get(105, type);
			if (sysAwards != null) {
				List<SubPops> subPops = sysAwards.getSubPopsList();
				int black = Context.getGoodsServer().checkSubPopsBlack(subPops);
				if (!player.getPlayerBoxs().checkBlack(black)) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", black));
				}
				Context.getGoodsServer().giveSubPops(subPops, player, logSB);
			}
		}
		
		int num = ConstantsModel.mmFlowerGold[type];//获得点数和花费元宝一致
		
		mmFlowerData.flower(session.getUid(), num);
		mmFlowerData.commitSync();
		int level = player.getLevel() > ConstantsLevel.lv1OnlineExp ? player.getLevel() : ConstantsLevel.lv1OnlineExp;//11级以下取11级的在线打坐经验
		int extGet = ConstantsModel.mmFlowerExpBase[type] * ModeExpConfig.getExpOnline(level);
		player.alterExp(extGet);
		
		if (!free) {
			player.alterGoldAll(-ConstantsModel.mmFlowerGold[type]);
			LogServer.costEventLog(session.getUid(), ConstantsModel.mmFlowerGold[type], ConstantsCost.mmFlower);
		} else {
			player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.comm, comm | ConstantsDayIntKey.comm_3);
			player.getDataInfo().commitSync();
		}
		player.commitSync();
		
		if (type >= 2) {
			EventNotice notice = new EventNotice(ConstantsRadio.holiday, ConstantsRadio.holiday_mmFlower);
			notice.put("type", type);
			notice.put("pName", player.getPlayerName());
			notice.put("mmid", mmId);
			notice.broadCastAllOnLine();
		}
		
		MMFlowerLog log = new MMFlowerLog();
		log.setN(num);
		log.setPid(session.getUid());
		log.setPn(player.getPlayerName());
		log.setSid(ConstantsConfig.getSysCgServiceId());
		log.setMid(mmId);
		mmFlowerData.addLog(log);
		
		LogServer.recordLog(player, ConstantsLog.activity, 90471, type, free, free ? 0 : ConstantsModel.mmFlowerGold[type], extGet, num,
				 logSB.toString(), MMFlowerData.getInstance().weekMapGet(session.getUid()),mmFlowerData.getFlowerNum(session.getUid()));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f", MMFlowerData.getInstance().weekMapGet(session.getUid()));
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		map.put("expGet", extGet);
		map.put("free", (player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.comm) & ConstantsDayIntKey.comm_3) == 0);
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 主播献花排行
	 * 
	 * @param session
	 * @param type
	 * 			1 单服 2 跨服
	 * @return
	 */
	@AccessClose
	public ResponseMessage mmFlowerRanking(Session session, int type) {
		
		Map<String, Object> map = new HashMap<String, Object>();
		if (type == 1) {
			map.put("sRanking", MMFlowerData.getInstance().getSilgleRanking());
		} if (type == 2) {
			return FlowerApiClient.mmFlowerTop();
		}
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 风筝显示
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage kiteShow(Session session) {
		if (KiteData.getInstance().chkActEnd()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr")); 
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv30kite) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv30kite);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ranking", KiteData.getInstance().getKiteRanking());
		map.put("m", KiteData.getInstance().getKite(session.getUid()));
		map.put("s", KiteData.getInstance().getLeaveScore(session.getUid()));
		map.put("free", ConstantsModel.kiteFreeMax - player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tkf));
		map.put("kg", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tkg));
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 放风筝
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	@AccessClose
	public ResponseMessage kiteEnjoy(Session session, int type) {
		if (type < 0 || type > 2) {
			return null;
		}
		if (KiteData.getInstance().chkActEnd()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr")); 
		}
		
		long playerId = session.getUid();
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (player.getLevel() < ConstantsLevel.lv30kite) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv30kite);
		}
		int kf = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tkf);
		boolean isFree = type == 0 && kf < ConstantsModel.kiteFreeMax ;
		if (!isFree && player.getGoldAll() < ConstantsModel.kiteGold[type]) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		
		KiteData.getInstance().alterKiteMap(playerId, ConstantsModel.kiteScore[type]);
		KiteData.getInstance().alterLeaveScore(playerId, ConstantsModel.kiteScore[type]);
		KiteData.getInstance().commitSync();
		if (isFree) { 
			player.getDataInfo().getEveryDay().intDataAlter(ConstantsDayIntKey.tkf, 1);
			player.getDataInfo().commitSync();
		} else {
			player.alterGoldAll(-ConstantsModel.kiteGold[type]);
			LogServer.costEventLog(playerId, ConstantsModel.kiteGold[type], ConstantsCost.kiteGold);
			player.commitSync();
		}
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120004, type, ConstantsModel.kiteGold[type], ConstantsModel.kiteScore[type], 
				KiteData.getInstance().getKite(playerId), KiteData.getInstance().getLeaveScore(playerId));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ranking", KiteData.getInstance().getKiteRanking());
		map.put("m", KiteData.getInstance().getKite(playerId));
		map.put("s", KiteData.getInstance().getLeaveScore(playerId));
		map.put("free", ConstantsModel.kiteFreeMax - player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tkf));
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 领取风筝奖励
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	@AccessClose
	public ResponseMessage kiteAward(Session session, int type) {
		if (type < 0 || type > 3) {
			return null;
		}
		if (KiteData.getInstance().chkActEnd()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr")); 
		}
		long playerId = session.getUid();
		Player player = Context.getPlayerServer().getByPlayerId(playerId);
		if (player.getLevel() < ConstantsLevel.lv30kite) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv30kite);
		}
		int kg = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tkg);
		boolean todayGot = (kg & 1 << type) > 0;
		if (todayGot) {
			return null;
		}
		int have = KiteData.getInstance().getLeaveScore(playerId);
		int cost = ConstantsModel.kiteAward[type][0];
		if (have < cost) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.kite.noenough"));
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		
		Context.getGoodsServer().giveGoodsBing(playerId, ConstantsModel.kiteAward[type][1], 1, 1);
		KiteData.getInstance().alterLeaveScore(playerId, -cost);
		KiteData.getInstance().commitSync();
		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.tkg, kg | 1 << type);
		player.getDataInfo().commitSync();
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsModel.kiteAward[type][1]);
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120005, type, cost, KiteData.getInstance().getLeaveScore(playerId), goodsMode.getName(), 1);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ranking", KiteData.getInstance().getKiteRanking());
		map.put("kg", player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tkg));
		map.put("m", KiteData.getInstance().getKite(playerId));
		map.put("s", KiteData.getInstance().getLeaveScore(playerId));
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 秦淮诗会显示
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage poetryShow(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < 30) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), 30);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("s", PoetryData.getInstance().getScore(session.getUid()));
		int freeUsed = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tpf);
		map.put("free", ConstantsModel.poetryFreeMax - freeUsed);
		map.put("pg", player.getDataInfo().intDataGet(ConstantsIntKey.tpog));
		map.put("expOnline", ModeExpConfig.getExpOnline(player.getLevel()));
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 秦淮诗会排行
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage poetryRanking(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < 30) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), 30);
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("ranking", PoetryData.getInstance().getRanking());
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 秦淮诗会对诗
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	@AccessClose
	public ResponseMessage poetryEnjoy(Session session, int type) {
		if (type < 0 || type > 2) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < 30) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), 30);
		}
		if (PoetryData.getInstance().chkEnd()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("holiday.comm.timeerr")); 
		}
		int freeUsed = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tpf);
		boolean isFree = type == 0 && ConstantsModel.poetryFreeMax - freeUsed > 0;
		if (!isFree && player.getGoldAll() < ConstantsModel.poetryCostGot[type][0]) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
		}
		
		int expGot = ConstantsModel.poetryCostGot[type][2] * ModeExpConfig.getExpOnline(player.getLevel());
		player.alterExp(expGot);
		
		PoetryData.getInstance().alterScore(session.getUid(), ConstantsModel.poetryCostGot[type][1]);
		PoetryData.getInstance().commitSync();
		
		if (isFree) {
			freeUsed++;
			player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.tpf, freeUsed);
			player.getDataInfo().commitSync();
		} else {
			player.alterGoldAll(-ConstantsModel.poetryCostGot[type][0]);
			LogServer.costEventLog(session.getUid(), ConstantsModel.poetryCostGot[type][0], ConstantsCost.poetryEnjoy);
		}
		player.commitSync();
		
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120011, type, isFree,isFree?0:ConstantsModel.poetryCostGot[type][0], 
				ConstantsModel.poetryCostGot[type][1], PoetryData.getInstance().getScore(session.getUid()),expGot);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		map.put("expGot", expGot);
		map.put("exp", player.getExp());
		map.put("s", PoetryData.getInstance().getScore(session.getUid()));
		map.put("free", ConstantsModel.poetryFreeMax - freeUsed);
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 领取秦淮诗会奖励
	 * 
	 * @param session
	 * @param type
	 * @return
	 */
	@AccessClose
	public ResponseMessage poetryAward(Session session, int type) {
		if (type < 0 || type > 3) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < 30) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), 30);
		}
		int score = PoetryData.getInstance().getScore(session.getUid());
		if (score < ConstantsModel.poetryAwardNeed[type]) {
			return null;
		}
		int pg = player.getDataInfo().intDataGet(ConstantsIntKey.tpog);
		boolean haveGot = (pg & 1 << type) > 0;
		if (haveGot) {
			return null;
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsModel.poetryAwardIds[type], 1, 1);
		
		pg = pg | 1 << type;
		player.getDataInfo().intDataSet(ConstantsIntKey.tpog, pg);
		player.getDataInfo().commitSync();
		
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120012, type, ConstantsModel.poetryAwardNeed[type],score,ConstantsModel.poetryAwardIds[type],1);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pg", pg);
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 寻找西施显示
	 * 
	 * @param session
	 * @return
	 */
	@AccessClose
	public ResponseMessage beautyShow(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv40Beauty) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv40Beauty);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		int curTaskId = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tbg) + 1;
		int[] state = ActTaskConfig.getTaskState(player, curTaskId);
		if (state != null) {
			map.put("state", state);
		}
		map.put("taskId", curTaskId);
		map.put("pg", player.getDataInfo().intDataGet(ConstantsIntKey.tbpg));
		map.put("s", player.getDataInfo().intDataGet(ConstantsIntKey.tbs));
		if (curTaskId == 6) {
			map.put("t", player.getDataInfo().getEveryDay().getUndercityTimes(903));//进入西施活动夫差副本次数
		}
		return ResponseMessage.getSuccMessage(map);
	}
	
	/**
	 * 领取寻找西施目标奖励 
	 * 
	 * @param session
	 * @param taskId
	 * @return
	 */
	@AccessFlag(ConstantsFlag.beautyAward)
	@AccessClose
	public ResponseMessage beautyAward(Session session, int taskId) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv40Beauty) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv40Beauty);
		}
		if (!ActTaskConfig.isContain(taskId)) {
			return null;
		}
		int g = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tbg);
		int awardSign = g + 1;
		if (awardSign > 5) {
			return null;
		}
		if (taskId != awardSign) {
			return null;
		}
		
		int[] taskState = ActTaskConfig.getTaskState(player, taskId);
		if (taskState[0] != 1) {
			return null;
		}
		
		StringBuffer logSB = new StringBuffer();
		SysModeAwards sysAwards = SysModeAwards.get(2005, taskId);
		if (sysAwards != null) {
			List<SubPops> subPops = sysAwards.getSubPopsList();
			int black = Context.getGoodsServer().checkSubPopsBlack(subPops);
			if (!player.getPlayerBoxs().checkBlack(black)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", black));
			}
			Context.getGoodsServer().giveSubPops(subPops, player, logSB);
		}
		int baseIndex = taskId >= 4 ? 2 : taskId >= 3 ? 1 : 0;
		int expGot = player.getLevel() * ConstantsModel.beautyExpBase[baseIndex];
		player.alterExp(expGot);
		player.commitSync();
		
		player.getDataInfo().intDataAlter(ConstantsIntKey.tbs, 2);//增加好感度
		
		player.getDataInfo().getEveryDay().intDataSet(ConstantsDayIntKey.tbg, awardSign);
		player.getDataInfo().commitSync();
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120014, taskId, logSB.toString(), expGot);
		Map<String, Object> map = new HashMap<String, Object>();
		int nextTask = taskId + 1;
		int[] state = ActTaskConfig.getTaskState(player, nextTask);
		if (state != null) {
			map.put("state", state);
		}
		map.put("taskId", nextTask);
		map.put(RMK.exp, player.getExp());
		map.put(RMK.expGot, expGot);
		map.put(RMK.asset, player.getAsset());
		map.put("s", player.getDataInfo().intDataGet(ConstantsIntKey.tbs));
		return ResponseMessage.getSuccMessage(map);

	}
	
	/**
	 * 领取西施宠物
	 * 
	 * @param session
	 * @return
	 */
	@AccessFlag(ConstantsFlag.beautyAward)
	@AccessClose
	public ResponseMessage beautyPetAward(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv40Beauty) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.level"), ConstantsLevel.lv40Beauty);
		}
		int g = player.getDataInfo().intDataGet(ConstantsIntKey.tbpg);
		if (g > 0) {
			return null;
		}
		int s = player.getDataInfo().intDataGet(ConstantsIntKey.tbs);
		if (s < ConstantsModel.beautyPetAward[0]) {
			return null;
		}
		if (!player.getPlayerBoxs().checkBlack()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}
		Context.getGoodsServer().giveGoodsBing(session.getUid(), ConstantsModel.beautyPetAward[1], 1, 1);
		
		g++;
		player.getDataInfo().intDataSet(ConstantsIntKey.tbpg, g);
		player.getDataInfo().commitSync();
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(ConstantsModel.beautyPetAward[1]);
		LogServer.recordLog(player, ConstantsLog.actWeek12, 120015, s, goodsMode.getName(), 1);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pg", g);
		return ResponseMessage.getSuccMessage(map);
	}
	
	
}
